package com.ruoyi.web.controller.coronary;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.coronary.domain.CoronaryRecord;
import com.ruoyi.coronary.service.ICoronaryRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 诊疗单Controller
 *
 * @author wky
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/coronary/record")
@Tag(name = "【诊疗单】管理")
public class CoronaryRecordController extends BaseController
{
    @Autowired
    private ICoronaryRecordService coronaryRecordService;

    /**
     * 查询诊疗单列表
     */
    @Operation(summary = "查询诊疗单列表")
    @PreAuthorize("@ss.hasPermi('coronary:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoronaryRecord coronaryRecord)
    {
        startPage();
        List<CoronaryRecord> list = coronaryRecordService.selectCoronaryRecordList(coronaryRecord);
        return getDataTable(list);
    }

    /**
     * 导出诊疗单列表
     */
    @Operation(summary = "导出诊疗单列表")
    @PreAuthorize("@ss.hasPermi('coronary:record:export')")
    @Log(title = "诊疗单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoronaryRecord coronaryRecord)
    {
        List<CoronaryRecord> list = coronaryRecordService.selectCoronaryRecordList(coronaryRecord);
        ExcelUtil<CoronaryRecord> util = new ExcelUtil<CoronaryRecord>(CoronaryRecord.class);
        util.exportExcel(response, list, "诊疗单数据");
    }

    /**
     * 获取诊疗单详细信息
     */
    @Operation(summary = "获取诊疗单详细信息")
    @PreAuthorize("@ss.hasPermi('coronary:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(coronaryRecordService.selectCoronaryRecordByRecordId(recordId));
    }

    /**
     * 新增诊疗单
     */
    @Operation(summary = "新增诊疗单")
    @PreAuthorize("@ss.hasPermi('coronary:record:add')")
    @Log(title = "诊疗单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoronaryRecord coronaryRecord)
    {
        return toAjax(coronaryRecordService.insertCoronaryRecord(coronaryRecord));
    }

    /**
     * 修改诊疗单
     */
    @Operation(summary = "修改诊疗单")
    @PreAuthorize("@ss.hasPermi('coronary:record:edit')")
    @Log(title = "诊疗单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoronaryRecord coronaryRecord)
    {
        return toAjax(coronaryRecordService.updateCoronaryRecord(coronaryRecord));
    }

    /**
     * 删除诊疗单
     */
    @Operation(summary = "删除诊疗单")
    @PreAuthorize("@ss.hasPermi('coronary:record:remove')")
    @Log(title = "诊疗单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable( name = "recordIds" ) Long[] recordIds)
    {
        return toAjax(coronaryRecordService.deleteCoronaryRecordByRecordIds(recordIds));
    }
}
